<!DOCTYPE html>
<html lang="zh-CN" style="height: 100%">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <script src="/static/js/echarts.min.js"></script>
    <link rel="stylesheet" href="/static/font/iconfont.css">
    <style>
        input {
            outline: none;
            -webkit-appearance: none;
            border-radius: 0;
            border-style: none;
            background-color: transparent;
        }

        .main {
            background: white;
            min-height: 490px;
            box-shadow: 1px 1px 2px #AAAAAA;
        }

        .layui-form-item {
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .layui-input-inline {
            width: 240px !important;
        }
    </style>
</head>
<body style="margin: 15px;height: 95%">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>修改密码</legend>
</fieldset>
<div class="layui-form main" style="height: 90%;">
    <div class="layui-form-item " style="padding-top: 10rem">
        <div class="layui-inline">
            <label class="layui-form-label">旧密码</label>
            <div class="layui-input-inline">
                <input type="password" class="layui-input" id="oldpwd">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="password" class="layui-input" id="pwd">
            </div>
        </div>
    </div>
    <div class="layui-form-item ">
        <div class="layui-inline">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input type="password" class="layui-input" id="pwd_a">
            </div>
        </div>
    </div>
    <div class="layui-form-item " style="padding-top: 2rem">
        <div class="layui-inline">
            <button class="layui-btn layui-btn-normal" style="background:#ff3366 " onclick="changePwd()">确认修改</button>
        </div>
    </div>
</div>

<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="/static/layui/layui.js"></script>
<script>
  var $, layer;
  layui.use('layer', function () {
    $ = layui.jquery;
    layer = layui.layer;
  });


  function changePwd() {
    var oldpwd = $('#oldpwd').val();
    var pwd = $('#pwd').val();
    var pwdA = $('#pwd_a').val();
    if (!oldpwd) {
      layer.msg('旧密码不能为空', {
        time: 2000,
      });
      return;
    }

    if (!pwd) {
      layer.msg('新密码不能为空', {
        time: 2000,
      });
      return;
    }
    if (pwd !== pwdA) {
      layer.msg('两次输入的新密码不一致', {
        time: 2000,
      });
      return;
    }
    $.post('/admin/changePassword?x-tm-token='
      + localStorage.tmToken, {
      oldPwd: oldpwd,
      newPwd: pwd
    }, function (data) {
      if (data.errno === 0) {
        layer.msg('修改密码成功', {
          time: 2000,
        });
        localStorage.tmToken = '';
        setTimeout("parent.window.location.href='/admin/login'", 2000);
      } else {
        layer.msg(data.errmsg, {
          time: 2000,
        });
      }
    });
  }
</script>
</body>
</html>